
*- naming glitch when collecting data 
rename enviro2_0 enviro3


*** if ends with L, then Likert
*** if ends with Lp, also Likert item but in the Likert+ treatment
*** if ends with Lpp1, Likert + version 1, from -5 to 5
*** if ends with Lpp2, Likert + version 2, from -8 to 8
*** if ends with Lpp3, Likert + version 3, used in main text, from -15 to 15 
*** if QV, then QV

**----------------------------
*** Preferences [check original qualtric codebook, a lot of re-coding was needed because
*** failed to code the survey in a coder-friendly manner]


*** Likert 
local issues AA gun wall paidL gender gay minW abortion deficit enviro

foreach var in `issues' {

gen `var'L = .
replace `var'L = -3 if `var'1 == 2 & `var'3 == 1
replace `var'L = -2 if `var'1 == 2 & `var'3 == 2
replace `var'L = -1 if `var'1 == 2 & `var'3 == 3
replace `var'L = 0 if `var'1 == 3 
replace `var'L = 1 if `var'1 == 1 & `var'2 == 3
replace `var'L = 2 if `var'1 == 1 & `var'2 == 2
replace `var'L = 3 if `var'1 == 1 &  `var'2 == 1

}

local issues AA gun wall paidL gender gay minW abortion deficit enviro

foreach var in `issues' {

gen `var'Lp = .
replace `var'Lp = -3 if `var'1plus == 2 & `var'3plus == 1
replace `var'Lp = -2 if `var'1plus == 2 & `var'3plus == 2
replace `var'Lp = -1 if `var'1plus == 2 & `var'3plus == 3
replace `var'Lp = 0 if `var'1plus == 3 
replace `var'Lp = 1 if `var'1plus == 1 & `var'2plus == 3
replace `var'Lp = 2 if `var'1plus == 1 & `var'2plus == 2
replace `var'Lp = 3 if `var'1plus == 1 &  `var'2plus == 1

replace `var'Lp = -3 if `var'1plus2 == 2 & `var'3plus2 == 1
replace `var'Lp = -2 if `var'1plus2 == 2 & `var'3plus2 == 2
replace `var'Lp = -1 if `var'1plus2 == 2 & `var'3plus2 == 3
replace `var'Lp = 0 if `var'1plus2 == 3 
replace `var'Lp = 1 if `var'1plus2 == 1 & `var'2plus2 == 3
replace `var'Lp = 2 if `var'1plus2 == 1 & `var'2plus2 == 2
replace `var'Lp = 3 if `var'1plus2 == 1 &  `var'2plus2 == 1

}


*** Likert + 
local issues AA gun wall paidL gender gay minW abortion deficit enviro

foreach var in `issues' {

gen `var'bi = 0 if `var'1plus == 3
replace `var'bi = 0 if `var'1plus2 == 3
replace `var'bi = -1 if `var'1plus == 2
replace `var'bi = -1 if `var'1plus2 == 2
replace `var'bi = 1 if `var'1plus ==1
replace `var'bi = 1 if `var'1plus2 == 1

}

rename minW3plus_0 minW4plus

local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {

gen `var'Lpp1 = . 
replace `var'Lpp1 = `var'bi * (6-`var'4plus)
replace `var'Lpp1 = `var'bi * (`var'4plus2)  if `var'Lpp1 == .
}


local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {

gen `var'Lpp2 = . 
replace `var'Lpp2 = `var'bi * ((4-`var'3plus) + (6-`var'4plus))
replace `var'Lpp2 = `var'bi * ((4-`var'3plus2) + (`var'4plus2)) if `var'Lpp2 == .
replace `var'Lpp2 = `var'bi * ((4-`var'2plus) + (6-`var'4plus) ) if `var'Lpp2 == .
replace `var'Lpp2 = `var'bi * ((4-`var'2plus2) + (`var'4plus2) )  if `var'Lpp2 == .
replace `var'Lpp2 = 0  if `var'Lpp2 == . & `var'bi == 0
}

local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {

gen `var'Lpp3 = . 
replace `var'Lpp3 = `var'bi * ((4-`var'3plus) * (6-`var'4plus))
replace `var'Lpp3 = `var'bi * ((4-`var'3plus2) * (`var'4plus2)) if `var'Lpp3 == .
replace `var'Lpp3 = `var'bi * ((4-`var'2plus) * (6-`var'4plus) ) if `var'Lpp3 == .
replace `var'Lpp3 = `var'bi * ((4-`var'2plus2) * (`var'4plus2) )  if `var'Lpp3 == .
replace `var'Lpp3 = 0  if `var'Lpp3 == . & `var'bi == 0
}



*** QV

rename QV1 QVgay
rename QV2 QVgun
rename QV3 QVwall
rename QV4 QVpaidL
rename QV5 QVAA
rename QV6 QVgender
rename QV7 QVminW
rename QV8 QVabortion
rename QV9 QVdeficit
rename QV10 QVenviro


local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {
destring QV`var', replace
}


******* issu important item for Table E8

local var gun wall gender paidL  minW abortion
foreach var in `var' {
gen `var'_IP = (6 - `var'4plus)
replace `var'_IP = `var'4plus2 if `var'_IP == .
}

******* Likert item for Likert+ treatment (first Likert item , before the issue importance item )



*** RECODE WALL / deficit / abortion [so that higher value more democratic response, lower value more republican response]


gen wall_inL = -1*wallL
gen QVwall_in = -1*QVwall
gen wall_inLpp1 = -1*wallLpp1
gen wall_inLpp2 = -1*wallLpp2
gen wall_inLpp3 = -1*wallLpp3

gen deficit_inL = -1*deficitL
gen QVdeficit_in = -1*QVdeficit
gen deficit_inLpp1 = -1*deficitLpp1
gen deficit_inLpp2 = -1*deficitLpp2
gen deficit_inLpp3 = -1*deficitLpp3

gen abortion_inL = -1*abortionL
gen QVabortion_in = -1*QVabortion
gen abortion_inLpp1 = -1*abortionLpp1
gen abortion_inLpp2 = -1*abortionLpp2
gen abortion_inLpp3 = -1*abortionLpp3




**----------------------------
*** SES variables

destring pid, replace
destring pid3, replace



*** white versus blak
recode ppethm( 1=1) ( 2 3 4 5 = 0), gen(white)
recode ppethm( 1=0) ( 2  5 = 1) (3 4 = .), gen(black_W)

*** reverse for material self-interest analysis (if non-black more supportive of AA)
gen whitea = 0 if white == 1
replace whitea = 1 if white == 0


*** latino / immigrant 
recode ppethm( 1=0) ( 2 3 5 = .) (4 = 1), gen(latino_W)


recode minWS1 (2 3 4 = 0), gen(working)
*** 

gen minW_hourly = .
*** hourly wage peeps, currently working 
replace minW_hourly = 1 if working ==  1 &  minWQ2a == 1 
replace minW_hourly = 1 if working ==  1 &  minWQ3a == 16 
replace minW_hourly = 1 if working ==  1 &  minWQ4a == 1
replace minW_hourly = 2 if working ==  1 &  minWQ5a == 1
replace minW_hourly =3 if working ==  1 &  minWQ5a == 2

*** hourly wage peeps, currently not working 
replace minW_hourly = 1 if working ==  0 &  minWQ2b == 1 
replace minW_hourly = 1 if working ==  0 &  minWQ3b == 16 
replace minW_hourly = 1 if working ==  0 &  minWQ4b == 1
replace minW_hourly = 2 if working ==  0 &  minWQ5b == 1
replace minW_hourly =3 if working ==  0 &  minWQ5b == 2

*** hourly wage peeps, currently not working but someone in HH
replace minW_hourly = 1 if working ==  0 &  minW_Q2c == 1 
replace minW_hourly = 1 if working ==  0 &  minW_Q3c == 16 
replace minW_hourly = 1 if working ==  0 &  minW_Q4c == 1
replace minW_hourly = 2 if working ==  0 &  minW_Q5c == 1
replace minW_hourly =3 if working ==  0 &  minW_Q5c == 2


*** minWa
** = 1 if below $15/h
** = 2 if right above 15$/h
** = 3 if much above 15$/h

*** salary peeps
gen minW_hourly2 = minW_hourly
replace minW_hourly2 = 1 if working ==  1 &  minWsal1a == 1 
replace minW_hourly2 = 2 if working ==  1 &  minWsal2a == 1 
replace minW_hourly2 = 3 if working ==  1 &  minWsal2a == 2

replace minW_hourly2 = 1 if working ==  0 &  minW_sal1b == 1 
replace minW_hourly2 = 2 if working ==  0 &  minW_sal2b == 1 
replace minW_hourly2 = 3 if working == 0 &  minW_sal2b == 2

replace minW_hourly2 = 1 if working ==  0 &  minW_sal1c == 1 
replace minW_hourly2 = 2 if working ==  0 &  minW_sal2c == 1 
replace minW_hourly2 = 3 if working ==  0 &  minW_sal2c == 2


gen minW = minW_hourly
replace minW = minW_hourly2 if minW == . 


*** generate a common variable for both an indicator for salary/hourly/nobody working
gen type_minW = .
replace type_minW = 0 if minW_hourly2 < .
replace type_minW = 1 if minW_hourly < .



**** reverse minW variable [if need to have positive coef : if benefit, then support], for material interest analysis 
gen minW_hourly2a = (-1 *minW_hourly2) + 4
gen minW_hourlya = (-1 *minW_hourly) + 4

gen minWa = minW_hourlya
replace minWa = minW_hourly2a if minWa == . 



***** gun , = 2 if gun in the house and own it
**, = 1 if gun in the house but does not own it
** = 0 if no gun in the house 

gen gunO = 0 if xppp20117 == 2
replace gunO = 2 if xppp20117 == 1 & xppp20122 == 1
replace gunO = 1 if xppp20117 == 1 & xppp20122 == 2

*** reverse for material interest analysis (no gun, more supportive of control)
gen gunOa = (-1*gunO)+ 4



** sexual orientation
recode xppalgb ( 1 3 4 = 1) (2 = 0), gen(gay)

*** vote
recode xpppa1690 ( 1=1) (2=2) (3= 3) ( 4 5 = 4), gen(vote16)


*** gender
rename ppgender sex


*** party id
recode xparty7 ( 1 /3 = 0) (4 = .) (5/7 = 1), gen(dem)
drop pid


*** religion 
recode xppp20071 ( 3 = .) (1=3), gen(evangelical)
**-- reverse for material-self int (not evangelical more supportive of abortion)
recode evangelical ( 3 = 0) ( 2  = 1) , gen(Nevangelical)


*** reli2, add attendance
** = 3 if evangelical who goes once a week or more
gen reli2 = 3 if evangelical == 3 & XREL2 < 3
replace reli2 = 2 if evangelical == 3 & XREL2 == 3 
replace reli2 = 1 if evangelical == 3 & XREL2 == 4 
replace reli2 = 1 if evangelical == 3 & XREL2 == 5
replace reli2 = 1 if evangelical == 3 & XREL2 == 6
replace reli2 = 0 if evangelical == 2
replace reli2 = -1 if evangelical == 2 & XREL2 < 3



*** children
** = 3 if has toddlers, plan to have kids soon
** = 2 if kids in the near future but not soon, or slightly older children
** = 1 if does not plan to have kids, kids are grown up 

** do you want children?
gen childA = .
replace childA = 5 if childQ4 == 1 |  childQ3 == 1
replace childA = 0 if childQ4 == 3 |  childQ3 == 3
replace childA = 2 if childQ4 == 4 |  childQ3 == 4
replace childA = 4 if childQ4 == 2 |  childQ3 == 2

** do you have children?
gen childB = .
replace childB = 4 if childQ2 == 1 |  childQ2 == 3
replace childB = 3 if childQ2 == 4 
replace childB = 2 if childQ2 == 5 
replace childB = 1 if childQ2 == 6 
replace childB = 0 if childQ1 == 2

gen child = childA + childB

recode child ( 0 1 = 1) ( 2 3 = 2) ( 4 5 6 7 8 9 = 3), gen(child2)


*** immi

recode  immiQ1 ( 1 2 3 = 0) (4 = 1), gen(FB)
recode immiQ2 (4 = .), gen(parents_immi)
recode immiQ3 (6 = .), gen(Gparents_immi)

factor FB parents_immi Gparents_immi
predict immiF






**----------------------------
*** create a variable that is common to all treatment conditions 



local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {

gen votes_`var'w1 = .
replace votes_`var'w1 = 0 if `var'L == 0 | `var'Lpp1 == 0 | QV`var' == 0
replace votes_`var'w1 = 1 if `var'L == 1 | `var'Lpp1 == 1 | QV`var' == 1
replace votes_`var'w1 = 2 if `var'L == 2 | `var'Lpp1 == 2 |  QV`var' == 2
replace votes_`var'w1 = 3 if `var'L == 3 | `var'Lpp1 == 3 | QV`var' == 3
replace votes_`var'w1 = 4 if  `var'Lpp1 == 4 | QV`var' == 4
replace votes_`var'w1 = 5 if  `var'Lpp1 == 5 | QV`var' == 5
replace votes_`var'w1 = QV`var' if QV`var' < . & votes_`var'w1 == . & method == 3 


replace votes_`var'w1 = -1 if `var'L == -1 | `var'Lpp1 == -1 | QV`var' == -1
replace votes_`var'w1 = -2 if `var'L == -2 | `var'Lpp1 == -2 |  QV`var' == -2
replace votes_`var'w1 = -3 if `var'L == -3 | `var'Lpp1 == -3 | QV`var' == -3
replace votes_`var'w1 = -4 if  `var'Lpp1 == -4 | QV`var' == -4
replace votes_`var'w1 = -5 if  `var'Lpp1 == -5 | QV`var' == -5
replace votes_`var'w1 = (-1) * QV`var' if QV`var' < . & votes_`var'w1 == . & method == 3 

}


**----------------------------
*** because too few people chose 10, 9 or 8, top code QVSR at 7 (-7)


local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {
recode votes_`var'w1 ( 10 9 8  = 7) ( -10 -9 -8  = -7) if method == 3
}



*-------------------------------
*--- Additional coding of variables of interest -- Lpp2 and Lpp3



local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {
gen votes_`var'w1LPP2 = votes_`var'w1
replace votes_`var'w1LPP2 = `var'Lpp2 if `var'Lpp2 < .
}



local issues AA gun wall paidL gender gay minW abortion deficit enviro
foreach var in `issues' {
gen votes_`var'w1LPP3 = votes_`var'w1
replace votes_`var'w1LPP3 = `var'Lpp3 if `var'Lpp3 < .
}



local issues wall abortion deficit 
foreach var in `issues' {
gen votes_`var'_inw1 = (-1) * votes_`var'w1
gen votes_`var'_inw1LPP2 = (-1) * votes_`var'w1LPP2
gen votes_`var'_inw1LPP3 = (-1) * votes_`var'w1LPP3
}



***


**----------------------------
*** NORMALIZE



local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
gen votes_`var'w1N = (votes_`var'w1 - (-3)) / (3 - (-3)) if method == 1
replace votes_`var'w1N = (votes_`var'w1 - (-5)) / (5 - (-5)) if method == 2
sum votes_`var'w1 if method == 3 
egen minQV`var' = min(votes_`var'w1) if method == 3
egen maxQV`var' = max(votes_`var'w1) if method == 3
replace votes_`var'w1N = (votes_`var'w1 - (minQV`var')) / (maxQV`var' - (minQV`var')) if method == 3
drop maxQV`var' minQV`var'
}



local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
capture drop abs_votes_`var'w1 abs_votes_`var'w1N
gen abs_votes_`var'w1 = abs(votes_`var'w1) 
gen abs_votes_`var'w1N = (abs_votes_`var'w1 - (0)) / (3 - (0)) if method == 1
replace abs_votes_`var'w1N = (abs_votes_`var'w1 - (0)) / (5 - (0)) if method == 2
egen minQV`var' = min(abs_votes_`var'w1) if method == 3
egen maxQV`var' = max(abs_votes_`var'w1) if method == 3
replace abs_votes_`var'w1N = (abs_votes_`var'w1 - (minQV`var')) / (maxQV`var' - (minQV`var')) if method == 3
drop maxQV`var' minQV`var'
}



*** Normalize [0-1] -- LPP2
local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
gen votes_`var'w1LPP2N = (votes_`var'w1LPP2 - (-3)) / (3 - (-3)) if method == 1
replace votes_`var'w1LPP2N = (votes_`var'w1LPP2 - (-8)) / (8 - (-8)) if method == 2
egen minQV`var' = min(votes_`var'w1LPP2) if method == 3
egen maxQV`var' = max(votes_`var'w1LPP2) if method == 3
replace votes_`var'w1LPP2N = (votes_`var'w1LPP2 - (minQV`var')) / (maxQV`var' - (minQV`var')) if method == 3
drop maxQV`var' minQV`var'
}



local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
gen abs_votes_`var'w1LPP2 = abs(votes_`var'w1LPP2) 
gen abs_votes_`var'w1LPP2N = (abs_votes_`var'w1LPP2 - (0)) / (3 - (0)) if method == 1
replace abs_votes_`var'w1LPP2N = (abs_votes_`var'w1LPP2 - (0)) / (8 - (0)) if method == 2
egen minQV`var' = min(abs_votes_`var'w1LPP2) if method == 3
egen maxQV`var' = max(abs_votes_`var'w1LPP2) if method == 3
replace abs_votes_`var'w1LPP2N = (abs_votes_`var'w1LPP2 - (minQV`var')) / (maxQV`var' - (minQV`var')) if method == 3
drop maxQV`var' minQV`var'

}


*** Normalize [0-1] -- LPP3
local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
gen votes_`var'w1LPP3N = (votes_`var'w1LPP3 - (-3)) / (3 - (-3)) if method == 1
replace votes_`var'w1LPP3N = (votes_`var'w1LPP3 - (-15)) / (15 - (-15)) if method == 2
egen minQV`var' = min(votes_`var'w1LPP3) if method == 3
egen maxQV`var' = max(votes_`var'w1LPP3) if method == 3
replace votes_`var'w1LPP3N = (votes_`var'w1LPP3 - (minQV`var')) / (maxQV`var' - (minQV`var')) if method == 3
drop maxQV`var' minQV`var'
}



local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
gen abs_votes_`var'w1LPP3 = abs(votes_`var'w1LPP3) 
gen abs_votes_`var'w1LPP3N = (abs_votes_`var'w1LPP3 - (0)) / (3 - (0)) if method == 1
replace abs_votes_`var'w1LPP3N = (abs_votes_`var'w1LPP3 - (0)) / (15 - (0)) if method == 2
egen minQV`var' = min(abs_votes_`var'w1LPP3) if method == 3
egen maxQV`var' = max(abs_votes_`var'w1LPP3) if method == 3
replace abs_votes_`var'w1LPP3N = (abs_votes_`var'w1LPP3 - (minQV`var')) / (maxQV`var' - (minQV`var')) if method == 3
drop maxQV`var' minQV`var'

}



local issues AA gun wall wall_in paidL gender gay minW abortion abortion_in deficit deficit_in enviro
foreach var in `issues' {
	corr votes_`var'w1N votes_`var'w1LPP2N votes_`var'w1LPP3N if method == 1
	corr votes_`var'w1N votes_`var'w1LPP2N votes_`var'w1LPP3N if method == 2
	corr votes_`var'w1N votes_`var'w1LPP2N votes_`var'w1LPP3N if method == 3
}




**----------------------------
*** DONATIONS, wave 1 outcome



*** categorical outcome 
gen dons = BG2_end_T
replace dons = 5 if BG2_donation_1 == 0
*-- donated or not 
tab dons, gen(don_bi)
*-- donated to anti gun (favor gun control) organization 
rename don_bi2 anti_gun
replace anti_gun = 0 if dons == . 
*-- donated to pro gun (oppose gun control) organization 
rename don_bi1 pro_gun
replace pro_gun = 0 if dons == . 
*** donated to pro wall / anti_immigration organization 
rename don_bi3 pro_wall_in
replace pro_wall_in = 0 if dons == . 
*** donated to anti wall / pro_immigration organization 
rename don_bi4 anti_wall_in
replace anti_wall_in = 0 if dons == . 


*** continuous outcome 
gen dons_C = BG2_donation_1
replace dons_C = 0 if BG2_end_T == 5

gen don_C_gun = dons_C if BG2_end_T == 2
replace don_C_gun = - dons_C if BG2_end_T == 1
replace don_C_gun = 0 if BG2_end_T == 3 | BG2_end_T == 4
***** (didn't want to donate at all after seeing the different organizations)
replace don_C_gun = 0 if dons == 5 
replace don_C_gun = . if dons == . 


gen don_C_wall_in = dons_C if BG2_end_T == 4
replace don_C_wall_in = - dons_C if BG2_end_T == 3
replace don_C_wall_in = 0 if BG2_end_T == 1 | BG2_end_T == 2
replace don_C_wall_in = 0 if dons == 5 
replace don_C_wall_in = . if  dons == . 




local issues don_C_gun don_C_wall_in 
foreach var in `issues' { 
sum `var', de
gen `var'ST = (`var' - r(mean)) / (r(sd) * 1)
}







